package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.ParkingMapper;
import com.jianglin.model.Parking;
import com.jianglin.service.IParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkingServiceImpl implements IParkingService {

    @Autowired
    private ParkingMapper parkingMapper;

    @Override
    public List<Parking> queryParkingAll() {
        return parkingMapper.findAll();
    }

    @Override
    public PageInfo<Parking> findParkAll(int page, int pageSize, String numbers) {
        PageHelper.startPage(page, pageSize);
        List<Parking> list = parkingMapper.queryParkAll(numbers);
        return new PageInfo<>(list);
    }

    @Override
    public List<Parking> queryParkingByStatus() {
        return parkingMapper.queryParkAllByStatus();
    }

    @Override
    public int add(Parking parking) {
        return parkingMapper.insert(parking);
    }

    @Override
    public int delete(Long id) {
        return parkingMapper.delete(id);
    }

    @Override
    public int updateData(Parking parking) {
        return parkingMapper.update(parking);
    }

    @Override
    public Parking findById(Long id) {
        return parkingMapper.findById(id);
    }

    // 使用PageHelper的分页查询
    @Override
    public PageInfo<Parking> findListByPage(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Parking> all = parkingMapper.findAll();
        return new PageInfo<>(all);
    }
}
